#include"process.h"

#define TARGET_SIZE 1024*1024 
#define DSIZE 1024*10

// void download()
// {
//   int target=TARGET_SIZE;
//   int total=0;
//   while(total<=target)
//   {
//     usleep(STIME);
//     total+=DSIZE;
//     process_v2(total*100/target);
//   }

// }
void download(callback_t cb)
{
    int testcnt = 100;
    int target = TARGET_SIZE;
    int total = 0;

    while(total <= target)
    {
        usleep(STIME); 
        total += DSIZE;
        double rate = total*100.0/target;
        if(rate > 50.0 && testcnt) {
            total = target/2;
            testcnt--;
        }
        cb(rate); 
    }
    cb(MAX_RATE); 
    printf("\n");
}

int main()
{
    download(process_v3);
    return 0;
}
